package page6;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Ques1435 {
	public void go(){
		Scanner scan = new Scanner(System.in);
		int n,m,m1,m2,s;
		String c;
		Set<Integer> set;
		List<Set<Integer>> list = new ArrayList<>();
		List<Set<Integer>> tempList = new ArrayList<>();
		while(scan.hasNext()){
			n = scan.nextInt();
			m = scan.nextInt();
			if(n == 0 && m == 0)break;
			set = new HashSet<>();
			list.add(set);
			while(m-- > 0){
				c = scan.next();
				if(c.equals("M")){
					m1 = scan.nextInt();
					m2 = scan.nextInt();
					boolean flag = false;
					for(Set<Integer> s1 : list){
						if(s1.contains(m1) || s1.contains(m2)){
							s1.add(m1);
							s1.add(m2);
							flag = true;
							break;
						}
					}
					if(!flag){
						set = new HashSet<>();
						set.add(m1);
						set.add(m2);
						tempList.add(set);
					}
					if(!tempList.isEmpty()){
						list.addAll(tempList);
						tempList.clear();
					}
				}else if(c.equals("S")){
					s = scan.nextInt();
					for(Set<Integer> s1 : list){
						if(s1.contains(s)){
							s1.remove(s);
							break;
						}
					}
				}
			}
			
			int sum = n;
			for(Set s1 : list){
				sum -= s1.size();
			}
			sum += list.size();
			System.out.println(sum - 1);
			list.clear();
			tempList.clear();
		}
	}
	
	public static void main(String[] args) {
		new Ques1435().go();
	}
}
